<template>
  <div class="detail_page">
    <Menus :title="name" :home="true" />
    <div :class="'article_content '+classs">
      <h2 class="title">{{item.title}}</h2>
      <div class="content" v-html="article_img(item.detail)">
      </div>
    </div>
  </div>
</template>
<script>
import Menus from '../components/Menu.vue'
import api from '../datas/api'
import typename from '../datas/typename'

export default {
  data() {
    return {
      name: '',
      item: ''
    }
  },
  methods: {
    article_img(html) {
      if (!html.includes('src=\"https://yn.12348.laway.cn/')) { // eslint-disable-line
        let dd = html.replace(/src="/g, 'src=\"https://yn.12348.laway.cn/') // eslint-disable-line
        dd = dd.replace(/background=\"\/image\/xxd.jpg\"/g, '') // eslint-disable-line
        return dd
      } else {
        return html
      }
    }
  },
  computed: {
    classs() {
      let c = ''
      if (this.name === '经典案例') {
        c = 'case-post'
      }
      return c
    }
  },
  async mounted() {
    const { id } = this.$route.params
    const item = await this.$get(api.post + id, this)
    this.item = item.result.data
    this.name = typename[item.diagram_id]
  },
  components: {
    Menus
  }
}
</script>
<style lang="scss">
a:hover,
a:link,
a:active,
a:visited {
  text-decoration: none;
  color: #333;
}

.detail_page {
  padding: 1.6rem 0 1rem;
  background: #ddd;
  min-height: 100vh;
  .article_content {
    width: 12rem;
    padding: 1rem;
    margin: 0.55rem auto 0;
    background-color: #fff;
    border-radius: 0.1rem;
    .title {
      font-size: 0.42rem;
      text-align: center;
      margin-bottom: 0.8rem;
    }
    .content {
      font-size: 0.24rem;
      line-height: 0.45rem;
      table {
        font-size: 0.18rem;
        td,
        th {
          padding: 0.15rem;
        }
      }
    }
  }
}

.case-post {
  .content {
    h5 {
      font-size: 0.18rem;
    }
    h2 {
      border-left: 0.1rem solid #3d69bd;
      font-size: 0.28rem;
      margin: 0.8rem 0 0.3rem;
      padding-left: 0.2rem;
    }
    h3 {
      margin: 0.35rem 0 0.2rem;
      font-size: 0.22rem;
      background: #eee;
      padding: 0.15rem;
      font-weight: normal;
      line-height: 1.7;
    }
    p {
      margin-bottom: 0.25rem;
      text-indent: 2em;
    }
  }
}
@media screen and (orientation: portrait) {
  .detail_page {
    .article_content {
      width: 90%;
      box-shadow: 0.1rem 0.1rem 0.3rem rgba(0, 0, 0, 0.05);
    }
  }
}
@media screen and (orientation: landscape) {
}
</style>
